
package ptaweek10;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class bokeyuan7 {
    public static void main(String[] args) {
      HashSet<String> set=new HashSet<String>();
      List<String> list=new ArrayList<String>();
      int m = 0;
      Scanner sc=new Scanner(System.in);
      String[] a=sc.nextLine().split(" ");
      for (String s : a) {
		set.add(s);
	}
      while(sc.hasNextLine()){
    	  String line=sc.nextLine();
    	  int i=line.length();
    	  while(i>=0){
    		  for(int j=i-1;j>=0;j--){
    			  String str=line.substring(j, i);
    			  if(set.contains(str)){
    				 list.add(str);
    				 m=str.length();
    			  }
    		  }
    		  i=i-m;
    	  }
    	  for(int k=list.size()-1;k>=0;k--){
    		  System.out.println(list.get(k));
    	  }
    	  list.clear();
      }
      
    }
}
 

